package com.example.myapplication.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;

import android.util.AttributeSet;
import android.view.View;

/**
 * 旋转
 * 作者：李祥
 * 邮箱：499194689@qq.com
 */

public class TestView04 extends View {
    Paint paint=new Paint();
    int mH;
    int mW;

    public TestView04(Context context) {
        super(context);
    }

    public TestView04(Context context,  AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        mH=h;
        mW=w;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.translate(mW/2,mH/2);

        RectF rectF=new RectF(0,-100,100,0);     //绘制矩形
        paint.setColor(Color.GREEN);                                      // 绘制黑色矩形
        canvas.drawRect(rectF,paint);

        canvas.rotate(90,20,0);                         // 旋转180度 <-- 默认旋转中心为原点
        paint.setColor(Color.BLUE);
        canvas.drawRect(rectF,paint);

        canvas.rotate(90,20,0);
        paint.setColor(Color.RED);
        canvas.drawRect(rectF,paint);

        canvas.rotate(90,20,0);
        paint.setColor(Color.YELLOW);
        canvas.drawRect(rectF,paint);

    }

}
